package com.rst.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.rst.dao.BookCategoryDAO;
import com.rst.dao.BookDAO;
import com.rst.dao.IssueBookDAO;
import com.rst.model.Book;
import com.rst.model.BookCategory;
import com.rst.model.IssueBook;

@Service
public class LibraryService {

	@Autowired
	private BookCategoryDAO bookCategoryDAO;
	
	@Autowired
	private BookDAO bookDAO ;
	
	@Autowired
	private IssueBookDAO issueBookDAO ;

	
	public void saveBookCategory(BookCategory bookCategory) {
		bookCategoryDAO.saveBookCategory(bookCategory);
		
	}

	public BookCategory getBookCategoryById(Long bookCategoryId) {
		return bookCategoryDAO.getBookCategoryById(bookCategoryId);
	}

	public List<BookCategory> getBookCategoryList() {
		return bookCategoryDAO.getBookCategoryList();	
	}

	public String deleteBookCategory(Long bookCategoryId) {
		 BookCategory bookCategory =  bookCategoryDAO.getBookCategoryById(bookCategoryId);
		 bookCategory.setStatus(BookCategory.INACTIVE);
		 bookCategoryDAO.saveBookCategory(bookCategory);
		return "success";
	}
	public void updateBookCategory(BookCategory bookCategory) {
		bookCategoryDAO.updateBookCategory(bookCategory);		
	}
	

	public void saveBook(Book book) {
		bookDAO.saveBook(book);		
	}

	public Book getBookById(Long bookId) {
		return bookDAO.getBookById(bookId);
	}

	public List<Book> getBooksList() {
		return bookDAO.getBooksList();	
	}

	public String deleteBook(Long bookId) {
		Book book = bookDAO.getBookById(bookId);
		book.setStatus(Book.INACTIVE);
		bookDAO.saveBook(book);
		return "success";
	}

	public Book getBookByBookNumber(Long bookNumber) {
		return bookDAO.getBookByBookNumber(bookNumber);	
	}

	public void saveIssueBook(IssueBook issueBook) {
		issueBookDAO.saveIssueBook(issueBook);			
	}

	public void updateBook(Book book) {
		 bookDAO.updateBook(book);			
	}


	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
